package cn.modoumama.common.tools;


import java.util.concurrent.*;

/**
 * 线程池管理<br>
 *
 * 创建人：邓强   <br>
 * 创建时间：2018/5/3/003 17:20    <br>
 * @version   V1.0
 */
public class ThreadUtils {

    private static ThreadPoolExecutor threadPoolExecutor;

    /**
     * 初始化时线程池大小为 200
     * @return
     */
    public static ThreadPoolExecutor getThreadPool() {
        if (threadPoolExecutor == null) {
            synchronized (ThreadUtils.class) {
                if (threadPoolExecutor == null) {
                    threadPoolExecutor = new ThreadPoolExecutor(0, 200, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
                }
            }
        }
        return threadPoolExecutor;
    }


    public static void main(String[] args) {
        ExecutorService threadPoolExecutor =getThreadPool();
        threadPoolExecutor.execute(new Runnable() {
            @Override
            public void run() {
                try {
                   //业务代码
                } catch (Exception e) {

                }
            }
        });
    }

}
